package com.lancoo.znbkxx.teacher.widget

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.WindowManager
import android.widget.PopupWindow
import androidx.recyclerview.widget.LinearLayoutManager
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.adapter.SpacesItemDecoration
import com.lancoo.znbkxx.teacher.diagnosis.ZsdAreaAdapter
import com.lancoo.znbkxx.teacher.model.data.ZsdArea
import com.lancoo.znbkxx.teacher.utils.DensityUtils
import kotlinx.android.synthetic.main.view_zsdarea.view.*

/**
 *@author Admin
 *@date 2020/12/29
 *
 */
class ZsdAreaPopupWindow(val data: List<ZsdArea>, val listener: ZsdAreaAdapter.OnSelectListener,
    val context: Context) : PopupWindow(context) {
    init {
        val view = LayoutInflater.from(context).inflate(R.layout.view_zsdarea, null)
        data[0].Checked = true
        val adapter = ZsdAreaAdapter(data, listener)
        view.rv_zsd.layoutManager = LinearLayoutManager(context)
        view.rv_zsd.adapter = adapter
        val hashMap = hashMapOf<String, Int>()
        hashMap[SpacesItemDecoration.TOP_SPACE] = DensityUtils.dp2px(context, 12f)
        view.rv_zsd.addItemDecoration(SpacesItemDecoration(hashMap))
        view.iv_close.setOnClickListener { dismiss() }
        contentView = view
        isFocusable = true
        setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        isOutsideTouchable = true
        animationStyle = R.style.PopupWindow
        width = WindowManager.LayoutParams.MATCH_PARENT
        height = WindowManager.LayoutParams.WRAP_CONTENT
        update()
    }
}